<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */

$workgroup = $records[0];
$assignedEmployees = $records[1];
$availableEmployees = $records[2];

$disabled = ($records['rights']['edit']) ? '' : 'disabled="disabled"';
?>
<script type="text/javascript" src="../../scripts/archive.js"></script>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<script type="text/javascript" src="../../scripts/common.js"></script>
<script type="text/javascript" src="../../scripts/jquery/jquery.js"></script>

<script type="text/javascript">
//<![CDATA[
var baseUrl = '?argcode=workgroup&action=';

function goBack() {
	location.href = "./CentralController.php?argcode=workgroup&action=View_Work_Groups";
}

function upateShift() {
	err=false;
	msg='<?php echo $lang_Error_PleaseCorrectTheFollowing; ?>\n\n';

	if ($('#txtShiftName').val().trim() == '') {
		err=true;
		msg+="\t- <?php echo $lang_Time_Error_SpecifyWorkShiftName; ?>\n";
	}

	if (err) {
		alert(msg);

		return false;
	}

	var assignedEmpObj = document.getElementById('cmbAssignedEmployees');
	//selectAllOptions($('cmbAssignedEmployees'));
	selectAllOptions(assignedEmpObj);
	document.getElementById('frmEditWorkShift').action=baseUrl+'Edit_Work_Group';
	document.getElementById('frmEditWorkShift').submit();
}

function assignEmployee() {
	var availiableEmpObj = document.getElementById('cmbAvailableEmployees');
	var assignedEmpObj = document.getElementById('cmbAssignedEmployees');
	//moveSelectOptions($('cmbAvailableEmployees'), $('cmbAssignedEmployees'), '<?php echo $lang_Time_Error_NoEmployeeSelected; ?>');
	moveSelectOptions(availiableEmpObj,assignedEmpObj, '<?php echo $lang_Time_Error_NoEmployeeSelected; ?>');
}

function removeEmployee() {
	var availiableEmpObj = document.getElementById('cmbAvailableEmployees');
	var assignedEmpObj = document.getElementById('cmbAssignedEmployees');
	//moveSelectOptions($('cmbAssignedEmployees'), $('cmbAvailableEmployees'), '<?php echo $lang_Time_Error_NoEmployeeSelected; ?>');
	moveSelectOptions(assignedEmpObj, availiableEmpObj, '<?php echo $lang_Time_Error_NoEmployeeSelected; ?>');
}


    
//]]>
</script>
    <div class="formpage">
        <div class="navigation">
            <input type="button" class="backbutton"
				onclick="goBack();" onmouseover="moverButton(this);" onmouseout="moutButton(this);"
				value="<?php echo $lang_Common_Back;?>" />
        </div>
        <div class="outerbox">
            <div class="mainHeading"><h2><?php echo $lang_Time_AssignEmployeesTitle;?></h2></div>
        
        <?php
            if (isset($_GET['message']) && !empty($_GET['message'])) {            
                $message  = $_GET['message'];
                $messageType = CommonFunctions::getCssClassForMessage($message);
                $message = "lang_Time_Errors_" . $message;
        ?>
            <div class="messagebar">
                <span class="<?php echo $messageType; ?>"><?php echo (isset($$message)) ? $$message: CommonFunctions::escapeHtml($_GET['message']); ?></span>
            </div>  
        <?php } ?>

	<form name="frmEditWorkShift" id="frmEditWorkShift" method="post" action="?argcode=workgroup&action=">
			<label for="txtShiftName">班次<span class="required">*</span></label>
	        <input type="text" id="txtShiftName" name="txtShiftName" tabindex="1" value="<?php echo $workgroup->getName(); ?>"
                class="formInputText"/>
        	<br class="clear"/>
        	<label for="txtShiftType">班次类别</label>
        	<select name="txtShiftType" id="txtShiftType" tabindex="2">
        		<option value="" <?php if($workgroup->getGroupType()=="") echo 'selected';?> >选择班次类别</option>
        		<option value="车间1班" <?php if($workgroup->getGroupType()=="车间1班") echo 'selected';?> >车间1班</option>
        		<option value="车间2班" <?php if($workgroup->getGroupType()=="车间2班") echo 'selected';?> >车间2班</option>
        		<option value="车间3班" <?php if($workgroup->getGroupType()=="车间3班") echo 'selected';?> >车间3班</option>
        		<option value="车间4班" <?php if($workgroup->getGroupType()=="车间4班") echo 'selected';?> >车间4班</option>
        		<option value="行政日班" <?php if($workgroup->getGroupType()=="行政日班") echo 'selected';?> >行政日班</option>
        		<option value="行政夜班" <?php if($workgroup->getGroupType()=="行政夜班") echo 'selected';?> >行政夜班</option>
        		<option value="保安1班" <?php if($workgroup->getGroupType()=="保安1班") echo 'selected';?> >保安1班</option>
        		<option value="保安2班" <?php if($workgroup->getGroupType()=="保安2班") echo 'selected';?> >保安2班</option>
        		<option value="保安3班" <?php if($workgroup->getGroupType()=="保安3班") echo 'selected';?> >保安3班</option>
        		<option value="保安4班" <?php if($workgroup->getGroupType()=="保安4班") echo 'selected';?> >保安4班</option>
        		<option value="厨房1班" <?php if($workgroup->getGroupType()=="厨房1班") echo 'selected';?> >厨房1班</option>
        		<option value="厨房2班" <?php if($workgroup->getGroupType()=="厨房2班") echo 'selected';?> >厨房2班</option>
        		<option value="厨房3班" <?php if($workgroup->getGroupType()=="厨房3班") echo 'selected';?> >厨房3班</option>
        		<option value="厨房4班" <?php if($workgroup->getGroupType()=="厨房4班") echo 'selected';?> >厨房4班</option>
        		<option value="厨房4班" <?php if($workgroup->getGroupType()=="厨房4班") echo 'selected';?> >厨房4班</option>
        		<option value="空白班" <?php if($workgroup->getGroupType()=="空白班") echo 'selected';?> >空白班</option>
        	</select>
        	<br class="clear"/>
	        <label for="txtHoursPerDay">组员总数</label>
	        <input type="text" id="txtHoursPerDay" name="txtHoursPerDay" tabindex="3" size="3" value="<?php echo $workgroup->getEmployeeQuantity(); ?>" class="formInputText" style="width:30px;"/>
        	<br class="clear"/>
	        <label for="txtGroupLeader">组长</label>
	        <input type="hidden" name="txtGroupLeader" id="txtGroupLeader" value="<?php echo $workgroup->getGroupLeader(); ?>" />
	        <input type="text" name="groupLeader" id="groupLeader" class="formInputText" 
			value="<?php echo $workgroup->getGroupLeader(); ?>" onblur="GetUserNameList('<?php echo $_SERVER['PHP_SELF']?>?argcode=workgroup&action=GetUserName','tbname','groupLeader','ShowUserName','txtGroupLeader')"/><br>
			<div id="ShowUserName" class="shownameclass" style="display:none"><table id="tbname" width="350" border="0" cellspacing="0" cellpadding="0"></table></div>
        	<br class="clear"/>
	        <label for="txtManager">负责经理</label>
	        <input type="hidden" name="txtManager" id="txtManager" value="<?php echo $workgroup->getManager(); ?>" />
	        <input type="text" name="manager" id="manager" class="formInputText" 
			value="<?php echo $workgroup->getManager(); ?>" onblur="GetUserNameList('<?php echo $_SERVER['PHP_SELF']?>?argcode=workgroup&action=GetUserName','tbname','manager','ShowUserName','txtManager')"/><br>
        	<br class="clear"/>
	        <label for="txtBoss">审批老板</label>
	        <input type="hidden" name="txtBoss" id="txtBoss" value="<?php echo $workgroup->getBoss(); ?>" />
	        <input type="text" name="boss" id="boss" class="formInputText" 
			value="<?php echo $workgroup->getBoss(); ?>" onblur="GetUserNameList('<?php echo $_SERVER['PHP_SELF']?>?argcode=workgroup&action=GetUserName','tbname','boss','ShowUserName','txtBoss')"/><br>
	        <input type="hidden" id="txtShiftId" name="txtShiftId" value="<?php echo $workgroup->getWorkgroupId(); ?>"/>
        	<br class="clear"/>
            <div class="formbuttons">           
                <input type="button" class="savebutton" <?php //echo $disabled; ?>
                    onclick="upateShift();" onmouseover="moverButton(this);" onmouseout="moutButton(this);"                          
                    value="<?php echo $lang_Common_Save;?>" />
            </div>
        <br class="clear"/>

		<table border="0">
		<tr>
		   	<th width="100" style="align:center;"><?php echo $lang_Time_AvailableEmployees; ?></th>
			<th width="100"/>
		   	<th width="125" style="align:center;"><?php echo $lang_Time_AssignedEmployees; ?></th>
		</tr>
		<tr><td width="100" >
			<select size="10" id="cmbAvailableEmployees" name="cmbAvailableEmployees[]" <?php //echo $disabled; ?>
				style="width:125px;" multiple="multiple">
       			<?php
       				foreach($availableEmployees as $employee) {
       					$empNum = $employee['emp_number'];
       					$name = $employee['emp_firstname'] . " " . $employee['emp_lastname'];
           				echo "<option value='{$empNum}'>{$name}</option>";
       				}
				?>
			</select></td>
			<td align="center" width="100">
				<input type="button" <?php //echo $disabled; ?> name="btnAssignEmployee" id="btnAssignEmployee" class="plainbtn"
					onmouseover="moverButton(this)" onmouseout="moutButton(this)"
					onclick="assignEmployee();" value=" <?php echo $lang_compstruct_add; ?> >" style="width:80%" /><br /><br />
				<input type="button" <?php //echo $disabled; ?> name="btnRemoveEmployee" id="btnRemoveEmployee" class="plainbtn"
					onmouseover="moverButton(this)" onmouseout="moutButton(this)"
					onclick="removeEmployee();" value="< <?php echo $lang_Leave_Common_Remove; ?>" style="width:80%" />
			</td>
			<td>
			<select size="10" name="cmbAssignedEmployees[]" id="cmbAssignedEmployees" <?php //echo $disabled; ?>
				style="width:125px;" multiple="multiple">
       			<?php
       				foreach($assignedEmployees as $employee) {
       					$empNum = $employee['emp_number'];
       					$name = $employee['emp_firstname'] . " " . $employee['emp_lastname'];
           				echo "<option value='{$empNum}'>{$name}</option>";
       				}
				?>
			</select></td>
		</tr>

	</table>
  </form>
</div>
<script type="text/javascript">
//<![CDATA[
    if (document.getElementById && document.createElement) {
        roundBorder('outerbox');                
    }
//]]>
</script>
</div>        
